package com.example.blog.controller.homework;

import com.example.blog.pojo.Result;
import com.example.blog.pojo.SendHomeWork;
import com.example.blog.service.CorrectService;
import com.example.blog.util.TokenUtil.GetCookie;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/corrects")
public class CorrectController {
    @Resource
    private CorrectService correctService;

    //批改任务
    @PostMapping("/correctHomework")
    public Result correctHomework(SendHomeWork sendHomeWork
            , @RequestParam int homeworkId
            , @RequestParam int score
            , @RequestParam String valuation
            , HttpServletRequest request) {
        String cookieValue = request.getHeader("Cookie");
        String token = GetCookie.getCookieValue(cookieValue);
        return correctService.correctHomework(sendHomeWork, homeworkId,score,valuation, token);
    }
    //查询用户自己提交任务的评分
    @GetMapping("/getUserScore")
    public Result getUserScore(@RequestParam int SendHomeworkId,HttpServletRequest request){
        String cookieValue = request.getHeader("Cookie");
        String token = GetCookie.getCookieValue(cookieValue);
        return correctService.getUserScore(SendHomeworkId,token);
    }

}
